//
//  UIView+iGallery.m
//  jingdongfang
//
//  Created by BOE on 2017/11/21.
//  Copyright © 2017年 LJL. All rights reserved.
//

#import "UIView+iGallery.h"

@implementation UIView (iGallery)

- (void)showTipsViewFromTop:(NSString *)tips
{
    UIView *view = [kKeyWindow viewWithTag:101];
    if (!view) {
        view = [[UIView alloc] initWithFrame:CGRectMake(0, -30, KSCREENWIDTH, 30)];
        view.tag = 101;
        view.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.6];
        [kKeyWindow addSubview:view];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 15, KSCREENWIDTH, 15)];
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor whiteColor];
        label.font = [UIFont systemFontOfSize:10.0];
        label.text = tips;
        [view addSubview:label];
    }
    
    [UIView animateWithDuration:0.5 animations:^{
        CGRect frame = view.frame;
        frame.origin.y = 0;
        [view setFrame:frame];
    } completion:^(BOOL finished) {
        [self performSelector:@selector(hideView:) withObject:view afterDelay:2.0];
    }];
}

- (void)hideView:(UIView *)view
{
    [UIView animateWithDuration:0.5 animations:^{
        CGRect frame = view.frame;
        frame.origin.y = -30;
        [view setFrame:frame];
    } completion:^(BOOL finished) {
        [view removeFromSuperview];
    }];
}
@end
